exports.serviceRecords = (req, res) => {

    var restfulParams = req.routeInfo.restfulParams;

    var resultData = {};

    var c_id = restfulParams.customerId;

    //查询服务记录
    function searchServiceRecord(cb) {

        R.SEND_HTTP(
            req,
            res,
            {
                url: CORE_APIConfig.coreAPI.artCustomerServiceSearch.Request_Api_Url + "/cs_is_delete/0/cs_cid/" + c_id+"/sort_order/cs_id-desc",
                method: 'POST',
                data: {
                    fields: ['cs_id', "cs_cid", "cs_uid", "cs_content", "cs_way", "cs_create_time"].join(",")
                }
            },
            function (data) {

                resultData.serviceRecord = data.result.data;

                cb();

            }
        )
    }

    function queryForEachSales(cb) {

        F.SerialEach(resultData.serviceRecord, function (item, index, callback) {

            //查询销售信息
            function salesInfo(eachCb) {

                R.SEND_HTTP(
                    req,
                    res,
                    {
                        url: CORE_APIConfig.coreAPI.userSearch.Request_Api_Url + "/u_is_delete/0/u_id/" + item.cs_uid,
                        method: 'POST',
                        data: {
                            fields: ['u_id', 'u_nickname', 'u_is_admin'].join(",")
                        }
                    },
                    function (data) {

                        if(data.result.data.length>0){
                            item.salesmanInfo = data.result.data[0];
                        }else{
                            item.salesmanInfo = '';
                        }

                        eachCb();

                    }
                )
            }

            F.Parallel([
                salesInfo,
            ], () => {
                callback();
            })

        }, cb)

    }

    F.Serial([
        searchServiceRecord,
        queryForEachSales,
    ], () => {
        RES.successResponse(res, resultData);
    })


}